package com.example.spidertp.handler;

import com.example.spidertp.common.ResponseEntity;
import com.example.spidertp.exception.BusinessException;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理器类
 * @RestControllerAdvice 针对接口Controller层面的返回处理
 *
 * @author xiong.bo
 * @version 1.0
 * @date 2022/9/24 5:44 下午
 */

@Component
@RestControllerAdvice
public class UnifiedExceptionHandler {


    /**
     * 捕获业务异常的返回
     *
     * @param e
     * @return
     */
    @ExceptionHandler(BusinessException.class)
    public ResponseEntity handlerBusinessException(BusinessException e) {
        return ResponseEntity.error(e.getCode(), e.getMessage());
    }

}
